<% layout('/layouts/default.html', {title: '生产工单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('生产工单管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btn-half-in" title="${text('半成品入库')}"><i class="fa fa-filter"></i> ${text('半成品入库')}</a>
				<a href="#" class="btn btn-default" id="btn-complete-in" title="${text('成品入库')}"><i class="fa fa-filter"></i> ${text('成品入库')}</a>
				<script>
					$("#btn-complete-in").click(function (){
						var rowIdArr=$('#dataGrid').dataGrid('getSelectRows');
						if(0==rowIdArr.length){
							js.showMessage("没有选择成品");
							return;
						}
						var select=[];
						for(var index in allData){

							var item=allData[index];
							if(-1 != rowIdArr.indexOf(item.id)){
								select.push(item);
								if (2 == item.stockInStatus) {
									js.showMessage(item.batchNumber + " 已入库");
									return;
								}
							}
						}
						js.addTabPage($(this),"成品入库","${ctx}/st/stInventoryBill/completeProductForm?isInsert=1&cpIds="+rowIdArr.join(","));
					});
					$("#btn-half-in").click(function (){
						var rowIdArr=$('#dataGrid').dataGrid('getSelectRows');
						var select=[];
						for(var index in allData){

							var item=allData[index];
							if(-1 != rowIdArr.indexOf(item.id)){
								select.push(item);
								if (2 == item.stockInStatus) {
									js.showMessage(item.batchNumber + " 已入库");
									return;
								}
								if(!item.materialCode){
									js.showMessage("非半成品，请在产品档案中设置，原材料编码");
									return;
								}
							}
						}
						js.addTabPage($(this),"半成品入库","${ctx}/st/stInventoryBill/completeProductForm?isInsert=1&half=1&cpIds="+rowIdArr.join(","));
					});
				</script>
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('st:stProductBill:edit')){ %>
					<a href="${ctx}/st/stProductBill/form" class="btn btn-default btnTool" title="${text('新增生产工单')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${stProductBill}" action="${ctx}/st/stProductBill/listDetailData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('单据号')}：</label>
					<div class="control-inline">
						<#form:input path="billNo" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('单据日期')}：</label>
					<div class="control-inline">
						<#form:input path="billDate" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('已生产数量')}：</label>
					<div class="control-inline">
						<#form:input path="hasProductNumber" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('是否研发')}：</label>
					<div class="control-inline width-120">
						<#form:select path="research" dictType="st_is_research" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('工单状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="billStatus" dictType="st_product_bill_status" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('计划完成日期')}：</label>
					<div class="control-inline">
						<#form:input path="plainCompleteDate" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('制作要求')}：</label>
					<div class="control-inline">
						<#form:input path="makeRequest" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('产品名称')}：</label>
					<div class="control-inline">
						<#form:input path="productName" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('本次配方')}：</label>
					<div class="control-inline">
						<#form:input path="thisFormula" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('工单类别')}：</label>
					<div class="control-inline width-120">
						<#form:select path="billType" dictType="st_product_bill_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('工单数量')}：</label>
					<div class="control-inline">
						<#form:input path="billNumber" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('每批重量')}：</label>
					<div class="control-inline">
						<#form:input path="perWeight" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('生产批次')}：</label>
					<div class="control-inline">
						<#form:input path="productBatch" maxlength="4" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('尾料上限')}：</label>
					<div class="control-inline">
						<#form:input path="tailingMaterialUpperLimit" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('尾料下限')}：</label>
					<div class="control-inline">
						<#form:input path="tailingMaterialLowerLimit" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('预混载体')}：</label>
					<div class="control-inline">
						<#form:input path="prepareMixCarrier" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('预混桶重量')}：</label>
					<div class="control-inline">
						<#form:input path="prepareMixWeight" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('回机料名称')}：</label>
					<div class="control-inline">
						<#form:input path="backMaterialName" maxlength="36" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('回机料重量')}：</label>
					<div class="control-inline">
						<#form:input path="backMaterialWeight" maxlength="8" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="approveState" dictType="st_approve_state" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批人编码')}：</label>
					<div class="control-inline">
						<#form:input path="approveManCode" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批人')}：</label>
					<div class="control-inline">
						<#form:input path="approveManName" maxlength="5" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	var allData;
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("单据号")}', name:'parentId.billNo', index:'a.bill_no', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			// return '<a href="${ctx}/st/stProductBill/form?id='+row.id+'" class="btnList" data-title="${text("编辑生产工单")}">'+(val||row.id)+'</a>';
			return val;
		}},
		{header:'${text("工单状态")}', name:'parentId.billStatus', index:'a.bill_status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_product_bill_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("入库状态")}', name:'stockInStatus', index:'a.bill_status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_product_bill_stock_in_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("产品名称")}', name:'parentId.productName', index:'a.product_name', width:150, align:"left"},
		{header:'${text("产品编码")}', name:'parentId.productCode', index:'a.product_name', width:150, align:"left"},
		{header:'${text("物料编码")}', name:'materialCode', index:'a.product_name', width:150, align:"left"},
		{header:'${text("本次配方")}', name:'parentId.thisFormula', index:'a.this_formula', width:150, align:"left"},
		{header:'${text("生产日期")}', name:'parentId.plainCompleteDate', index:'a.this_formula', width:150, align:"left"},
		{header:'${text("规格")}', name:'specification', index:'a.this_formula', width:150, align:"left"},
		{header:'${text("批号")}', name:'batchNumber', index:'a.this_formula', width:150, align:"left"},
		{header:'${text("每批重量")}', name:'parentId.perWeight', index:'a.per_weight', width:150, align:"center"},
		{header:'${text("件数")}', name:'caseNumber', index:'a.product_batch', width:150, align:"left"},
		{header:'${text("审批状态")}', name:'parentId.approveState', index:'a.approve_state', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('st_approve_state')}, val, '${text("未知")}', true);
		}},
		{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('st:stProductBill:edit')){ %>
				actions.push('<a href="${ctx}/st/stProductBill/form?id='+row.id+'" class="btnList" title="${text("编辑生产工单")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/st/stProductBill/delete?id='+row.id+'" class="btnList" title="${text("删除生产工单")}" data-confirm="${text("确认要删除该生产工单吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	showCheckbox: true,
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		allData=data.list;
	}
});
</script>